package com.efesco.unite_query;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.efesco.common.CommUtil;

/**
 * employee_manageViewModel
 */
public class company_manageViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters)
      throws Exception {
	  String state=(String)parameters.getValue("state");
	  Dataset ds1=getDataset("dataset_company_operation");
	  Dataset ds2=getDataset("dataset_company_field");
	  Dataset ds3=getDataset("dataset_company_field_sub");
	  if(state.equalsIgnoreCase("del")){
		  datadel(ds1,"S_QUERY_OPERATION_C","QUERY_OPERATION_ID"); 
		  datadel(ds2,"S_QUERY_FIELD_C","QUERY_FIELD_ID");
		  datadel(ds3,"S_QUERY_FIELD_SUB_C","QUERY_FIELD_SUB_ID");
	  }else{
	  if(!ds1.isLast()) 
		   util.doUpdateData(ds1,"S_QUERY_OPERATION_C","QUERY_OPERATION_ID");
	
	  if(!ds2.isLast())
		   util.doUpdateData(ds2,"S_QUERY_FIELD_C","QUERY_FIELD_ID");
	
	  if(!ds3.isLast())
		   util.doUpdateData(ds3,"S_QUERY_FIELD_SUB_C","QUERY_FIELD_SUB_ID");
	  
	  }
 
   //super.doUpdateData(parameters);
  }
private void datadel(Dataset dataset,String table,String kid){
	RecordIterator iter = dataset.recordIterator();
	DBStatement dbs = new DBStatement();
	while (iter.hasNext()) {
		Record record = iter.nextRecord();
		dbs.setSql("delete from "+table+" where "+kid+"="+record.getValue(kid));
		try {
			dbs.execute();
		} catch (Exception e) {
			e.printStackTrace();
		}
		//dataset.deleteRecord(record.getValue(kid));
	}
	dbs.close();
}
}
